//
//  WBTabBar.m
//  OC版新浪微博
//
//  Created by chenguanglei on 16/12/3.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "WBTabBar.h"


@implementation WBTabBar


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}

-(void)layoutSubviews{

    [super layoutSubviews];
    
    CGFloat itemH = self.bounds.size.height;
    
    CGFloat itemW = self.bounds.size.width/5;
    
    NSInteger index = 0;
    
    for (UIView *tab in self.subviews) {
        
        if ([tab isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            tab.frame = CGRectMake(index*itemW, 0, itemW, itemH);
            
            index == 1 ? (index+=2) : (index++);
            
        }
       
        if ([tab isKindOfClass:NSClassFromString(@"UIButton")]) {
            
            tab.frame = CGRectMake(2*itemW, 0, itemW, itemH);
            
        }
        
        
    }
    

}


- (void)setupUI{

    
    UIButton *plusButton = [[UIButton alloc]init];
    
    [plusButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [plusButton setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
    
    [plusButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [plusButton setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];

    [plusButton addTarget:self action:@selector(plusButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:plusButton];

}


- (void)plusButtonClick:(UIBarButtonItem *)button{

    NSLog(@"加号按钮,%@",button);

}


@end
